from django.db import models
from django.utils import timezone


# Create your models here.

class articles(models.Model):
    # 文章id
    articles_id = models.AutoField(primary_key=True)
    # 发表用户id
    user_id = models.BigIntegerField()
    # 文章作者
    articles_host = models.CharField(verbose_name="作者", max_length=50)
    # 文章标签
    articles_label = models.CharField(verbose_name="标签", max_length=100, blank=True, null=True)
    # 文章标题
    articles_title = models.TextField(verbose_name="标题", default="暂时还没有往里面添加内容")
    # 文章内容
    articles_content = models.TextField(verbose_name="文本内容", default="暂时还没有往里面添加内容")
    # 文章浏览量
    articles_views = models.BigIntegerField(default=0, null=True)
    # 文章存在状态，1为在存在，0为被删除
    articles_status = models.IntegerField(blank=True, null=True, default=1)
    # 文章评论总数
    articles_comment_count = models.BigIntegerField(null=True, default=0)
    # 发表日期
    articles_date = models.DateTimeField(default=timezone.now)
    # 点赞总数
    articles_like_count = models.BigIntegerField(default=0, null=True)
    # 点赞用户id
    like_user_id = models.BigIntegerField(null=True)
    # 收藏总数
    articles_favorite = models.BigIntegerField(default=0, null=True)
    # 收藏用户id
    favorite_user_id = models.BigIntegerField(null=True)

    # 文章类型
    level_choices = (
        (1, "原创"),
        (2, "转载"),
        (3, "翻译"),
    )
    level = models.SmallIntegerField(verbose_name="文章类型", choices=level_choices, default=1)

    def __str__(self):
        return self.articles_title

    class Meta:
        db_table = 'articles'


class like_user(models.Model):
    # 自增id
    articles_like_user_id = models.AutoField(primary_key=True)
    # 收藏文章
    article_id = models.BigIntegerField()
    # 收藏用户
    like_user_id = models.BigIntegerField()

    class Meta:
        db_table = 'like_user'


# 收藏用户中间表
class favorite_user(models.Model):
    # 自增id
    favorite_user_id = models.AutoField(primary_key=True)
    # 收藏文章
    article_id = models.BigIntegerField()
    # 收藏用户
    like_user_id = models.BigIntegerField()

    class Meta:
        db_table = 'favorite_user'


class comment(models.Model):
    # 评论id
    comment_id = models.AutoField(primary_key=True)
    # 评论用户姓名
    commenter_name = models.CharField(max_length=20, default='')
    # 用户id
    user_id = models.BigIntegerField()
    # 评论博文id
    articles_id = models.BigIntegerField()
    # 评论内容
    comment_content = models.TextField(verbose_name="评论内容", default="暂时还没有往里面添加内容")
    # 评论日期
    comment_date = models.DateTimeField(default=timezone.now)
    # 评论点赞数
    comment_like = models.BigIntegerField(default=0)
    # 子评论id
    son_comment_id = models.BigIntegerField()

    def __str__(self):
        return self.comment_content

    class Meta:
        db_table = 'comment'

# 文章评论表（多对多中间表）
# class articles_comment(models.Model):
#     articles_comment_id = models.AutoField(primary_key=True)
#     articles_id = models.BigIntegerField()
#     comment_id = models.BigIntegerField()
#
#     class Meta:
#         db_table = 'articles_comment'


